<?php
$showStats = true;
include_once ("includes/header.php");

uasort($teams->teams, "leagueSort");
$averages = array ();
foreach ($teams->teams as $team) {
    array_push($averages, new TeamAverage($team));
}
$adjusteds = array ();
foreach ($teams->teams as $team) {
    array_push($adjusteds, new AdjustedAverage($team));
}

$sort = $_GET["sort"];
switch ($sort) {
    case 1 :
        uasort($averages, "sortMA");
        uasort($adjusteds, "sortMA");
        break;
    case 2 :
        uasort($averages, "sortST");
        uasort($adjusteds, "sortST");
        break;
    case 3 :
        uasort($averages, "sortAG");
        uasort($adjusteds, "sortAG");
        break;
    case 4 :
        uasort($averages, "sortAV");
        uasort($adjusteds, "sortAV");
        break;
    case 5 :
        uasort($averages, "sortCost");
        uasort($adjusteds, "sortCost");
        break;
    case 6 :
        uasort($averages, "sortBest11");
        uasort($adjusteds, "sortBest11");
        break;
}

echo<<< EOQ
            <caption><h1>Team Averages</h1></caption>
            <tr align="center">
              <th>Team</th>
              <th>Race</th>
              <th><a href="?sort=1">MA</a></th>
              <th><a href="?sort=2">ST</a></th>
              <th><a href="?sort=3">AG</a></th>
              <th><a href="?sort=4">Av</a></th>
              <th><a href="?sort=5">Cost</a></th>
              <th><a href="?sort=6">Best 11 Cost</a></th>
            </tr>

EOQ;

$i = 1;
foreach ($averages as $average) {
    $average->echoRow($i++);
}

echo<<< EOQ
            <tr>
              <th colspan="8" align="center"><br />Adjusted Averages</th>
            </tr>\n
            <tr align="center">
              <th>Team</th>
              <th>Race</th>
              <th><a href="?sort=1">MA</a></th>
              <th><a href="?sort=2">ST</a></th>
              <th><a href="?sort=3">AG</a></th>
              <th><a href="?sort=4">Av</a></th>
              <th><a href="?sort=5">Cost</a></th>
              <th><a href="?sort=6">Best 11 Cost</a></th>
            </tr>

EOQ;

$i = 1;
foreach ($adjusteds as $average) {
    $average->echoRow($i++);
}

echo<<< EOQ
            <tr>
              <td colspan="8" align="left"><br />Note Av is calculated against probability of penetration. So a player with Av 7 and Av 9 have an average of 7.9, not 8 as you might expect.
              </td>
            </tr>
            <tr>
              <td colspan="8" align="left"><br />Comments on Adjusted Averages<br />
                <ul>
                  <li><b>MA :-</b> Measures relative speed around the pitch. Each Skill is treated a 0.25-1 extra points of MA.
                    <br /><i>&nbsp;&nbsp;&nbsp;Sprint, Sure Feet, Jump Up, Dodge, Break Tackle, Stand Firm</i></li>
                  <li><b>ST :-</b> Measures ability to block and injury your opponent. Unlike the other averages base St plays a relatively small part in the total. High ST player gain more from skills than low ST players.
                    <br /><i>&nbsp;&nbsp;&nbsp;Block, Tackle, Guard, Pro, Mighty Blow, Claw, Razor Sharp Claws, Piling On, Dirty Player, Frenzy</i></li>
                  <li><b>AG :-</b> Measures ability to pass the ball and dodge through enemy lines. Each Skill is adds between 0.1 and 0.4 extra point of AG. Low AG players gain more from skills than high AG players.
                    <br/><i>&nbsp;&nbsp;&nbsp;Dodge, Pass, Break Tackle, Sure Hands, Big Hand, Catch, Accurate, Strong Arm, Catch, Leap, Stand Firm, Nerves Of Steel</i></li>
                  <li><b>Av :-</b> Measures ability to resist damage.
                    <br/><i>&nbsp;&nbsp;&nbsp;Block, Dodge, Thick Skull, Foul Appearance</i></li>
                  <li><b>Cost :-</b> Cost to buy the player, adjusted for additional skills and stat increases. ST 30k, AG 20k, Block 20k, rest 10k. Stat decreases and niggling injuries are accounted for too.
                </ul>
              </td>
            </tr>

EOQ;

include ("includes/footer.php");
?>
